<template>
    <view class="container">
		<view class="cu-card">
			<view class="cu-item shadow-warp" v-for="(item, index) in orderItems" :key="index" @click="goToDetail(item.projectid)">
				<view class="border-b-line bg-red radius">
					<view class="cu-list grid col-2 no-border" style="background: none;">
						<view class="cu-item">
							<text class="text-left margin-left text-cut">{{ item.projectname }}</text>
						</view>
<!-- 						<view class="cu-item">
							<text class="text-right margin-right">购买数量：{{ item.num }}</text>
						</view> -->
					</view>
				</view>
				<view class="text-content" style="background-color: #F9F9FC;">
					<view class="cu-list grid col-2 no-border text-sm">
						<view class="cu-item" style="width: 300rpx;">
							<image style="width: 240rpx;height: 280rpx"  mode="" :src="weburl + item.projectimg" ></image>
						</view>
						<view class="cu-item" style="width: 380rpx;">
							<view class="flex">
								<text class="text-gray">产品名称：</text>
								<text class="text-black text-df">{{ item.projectname }}</text>
							</view>							
							<view class="flex">
								<text class="text-gray">产品价格：</text>
								<text class="text-black text-df">{{ item.projectprice }}元</text>
							</view>
							<view class="flex">
								<text class="text-gray">收益周期：</text>
								<text class="text-black text-df">{{ item.projectday }}天</text>
							</view>
							<view class="flex">
								<text class="text-gray">收益：</text>
								<text class="text-black text-df">￥{{ item.projectrate }}/天</text>
							</view>
							<view class="flex">
								<text class="text-gray" style="white-space: nowrap">收藏时间：</text>
								<text class="text-black">{{ item.create_time }}</text>
							</view>

						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="uni-loadmore" v-if="showLoadMore">{{loadMoreText}}</view>
    </view>
</template>
<script>
	export default {
        data() {
            return {
				modalName: null,
				orderItems: [],
				page: 1,
				lastPage: 0,
				loadMoreText: "加载中...",
				showLoadMore: true
            }
        },
		onUnload() {
			this.page = 1,
			this.lastPage = 0,
			this.list = [],
			this.loadMoreText = "加载中...",
			this.showLoadMore = true;
		},
		onLoad: function (option) {
            this.getData();
		},
		onReachBottom() {
			// console.log("onReachBottom");
			if (this.page >= this.lastPage) {
				this.loadMoreText = "没有更多数据了!"
				return;
			}else{
				setTimeout(() => {
					this.getData();
				}, 300);
			}
		},
		onPullDownRefresh() {
			this.page = 1,
			this.lastPage = 0,
			this.list = [],
			this.loadMoreText = "加载更多",
			
			setTimeout(() => {
				this.getData();
			}, 300);
		},
		methods: {		
            getData: function() {
				//获取基础参数
				// uni.showLoading({
				// 	title:"数据加载中",
				// 	mask:true
				// })

				let page = this.page;
				let info = uni.getStorageSync("userinfo");
				let timestamp = this.helper.now();
				let sign = this.helper.setSign(['page='+page,'token='+info.token,'timestamp='+timestamp]);
				this.helper.req({
					api:"getFav",
					timestamp:timestamp,
					data:{page:page,token:info.token},
					header:{sign:sign},
					method:'GET',
				}).then(res=>{
					console.log('数据',res.data.data.data)
					let current_page = res.data.data.current_page;
					let last_page = res.data.data.last_page;
					this.page = current_page + 1;
					this.lastPage = last_page;
					this.orderItems = res.data.data.data;
					
					if (this.page >= this.lastPage) {
						this.loadMoreText = "没有更多数据了!"
					}
					uni.stopPullDownRefresh();
					uni.hideLoading();
				})
            },
            navToDetails: function(a) {
                uni.navigateTo({
                    url: "/pages/invest/invest?code=" + a.id
                })
            },
            navToContract: function(a) {
                uni.navigateTo({
                    url: "/pages/invest/contract?code=" + a.id
                })
            },
			goToDetail(id) {
					uni.navigateTo({
						url: '/pages/invest/detail?id=' + id
					});
				}
			},	
		}
</script>

<style lang="scss">
.panel-scroll-box{
	height: 100%;
	
	.panel-item{
		background: #fff;
		padding: 30px 0;
		border-bottom: 2px solid #000;
	}
}
.cu-list.grid.no-border{
	padding: 0;
}
.cu-list + .cu-list{
	margin: 0;
}
</style>